package cn.com.hp.feature.onfig;

import cn.com.hp.feature.util.ToolUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author hjz token filter
 */
@Component
@Slf4j
public class HeaderFilter extends HandlerInterceptorAdapter {

    private static String USER_ID = "userId";
    private static String tenantId = "HP";
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        String userIdString = request.getHeader(USER_ID);
        String tenantIdString = request.getHeader("tenantId");


        if (ToolUtil.isNotEmpty(userIdString)){
            UserProperties.setCurrentUserId(userIdString,tenantIdString);
        }
        return true;
    }

}
